/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.struts.service.beans;

import java.util.ArrayList;
import java.util.List;


/**
 * This class corresponds to the "menu" element of the menus_conf.xml file.
 * This is a menu associated with a profile.<br>
 * Several profiles should have menus with same name, but contents should depend
 * on profile. This allows the application to transparently display
 * profiles specific menus elements, always referring to the same menu.
 *
 */
public class JBMenu
{
    /** Menu name. */
    private String name;

    /** Menu elements (JBMenuElement). */
    private List elements = new ArrayList();

    /**
     * Returns the menu name.
     * @return name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Sets the menu name.
     * @param aname The name to set
     */
    public void setName(String aname)
    {
        this.name = aname;
    }

    /**
     * Returns the menu elements.
     * @return List of JBMenuElement
     */
    public List getElements()
    {
        return elements;
    }

    /**
     * Sets the menu elements.
     * @param aelements The list of JBMenuElement to set
     */
    public void setElements(List aelements)
    {
        this.elements = aelements;
    }

    /**
     * Adds a menu element.
     *
     * @param elt menu element to add
     */
    public void addElement(JBMenuElement elt)
    {
        elements.add(elt);
    }

    /**
     * Displays the menu definition.
     *
     * @return String formatted menu definition.
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        buf.append("name = ");
        buf.append(name);
        buf.append(System.getProperty("line.separator"));

        if (elements != null)
        {
            buf.append("List components of elements = ");
            buf.append(System.getProperty("line.separator"));
            it = elements.iterator();

            while (it.hasNext())
            {
                buf.append("...");
                buf.append(it.next());
                buf.append(System.getProperty("line.separator"));
            }
        }

        return buf.toString();
    }

    // end of toString method
}
